.class public abstract Lcom/sponsorpay/sdk/android/advertiser/AbstractCallbackSender;
.super Landroid/os/AsyncTask;
.source "AbstractCallbackSender.java"


# annotations
.annotation system Ldalvik/annotation/Signature;
    value = {
        "Landroid/os/AsyncTask",
        "<",
        "Ljava/lang/String;",
        "Ljava/lang/Void;",
        "Ljava/lang/Boolean;",
        ">;"
    }
.end annotation


# static fields
.field private static final INSTALL_SUBID_KEY:Ljava/lang/String; = "subid"

.field protected static final SUCCESFUL_HTTP_STATUS_CODE:I = 0xc8

.field protected static final SUCCESSFUL_ANSWER_RECEIVED_KEY:Ljava/lang/String; = "answer_received"


# instance fields
.field private mCredentials:Lcom/sponsorpay/sdk/android/credentials/SPCredentials;

.field private mCustomParams:Ljava/util/Map;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/Map",
            "<",
            "Ljava/lang/String;",
            "Ljava/lang/String;",
            ">;"
        }
    .end annotation
.end field

.field protected mState:Lcom/sponsorpay/sdk/android/advertiser/SponsorPayAdvertiserState;


# direct methods
.method public constructor <init>(Lcom/sponsorpay/sdk/android/credentials/SPCredentials;Lcom/sponsorpay/sdk/android/advertiser/SponsorPayAdvertiserState;)V
    .locals 0
    .parameter "credentials"
    .parameter "state"

    .prologue
    .line 66
    invoke-direct {p0}, Landroid/os/AsyncTask;-><init>()V

    .line 67
    iput-object p2, p0, Lcom/sponsorpay/sdk/android/advertiser/AbstractCallbackSender;->mState:Lcom/sponsorpay/sdk/android/advertiser/SponsorPayAdvertiserState;

    .line 68
    iput-object p1, p0, Lcom/sponsorpay/sdk/android/advertiser/AbstractCallbackSender;->mCredentials:Lcom/sponsorpay/sdk/android/credentials/SPCredentials;

    .line 69
    return-void
.end method

.method private buildUrl()Ljava/lang/String;
    .locals 6

    .prologue
    .line 92
    invoke-virtual {p0}, Lcom/sponsorpay/sdk/android/advertiser/AbstractCallbackSender;->getParams()Ljava/util/Map;

    move-result-object v2

    .line 93
    .local v2, params:Ljava/util/Map;,"Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;"
    if-nez v2, :cond_0

    .line 94
    new-instance v2, Ljava/util/HashMap;

    .end local v2           #params:Ljava/util/Map;,"Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;"
    invoke-direct {v2}, Ljava/util/HashMap;-><init>()V

    .line 97
    .restart local v2       #params:Ljava/util/Map;,"Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;"
    :cond_0
    iget-object v3, p0, Lcom/sponsorpay/sdk/android/advertiser/AbstractCallbackSender;->mCustomParams:Ljava/util/Map;

    if-eqz v3, :cond_1

    .line 98
    iget-object v3, p0, Lcom/sponsorpay/sdk/android/advertiser/AbstractCallbackSender;->mCustomParams:Ljava/util/Map;

    invoke-interface {v2, v3}, Ljava/util/Map;->putAll(Ljava/util/Map;)V

    .line 101
    :cond_1
    const-string v3, "answer_received"

    .line 102
    invoke-virtual {p0}, Lcom/sponsorpay/sdk/android/advertiser/AbstractCallbackSender;->getAnswerReceived()Ljava/lang/String;

    move-result-object v4

    .line 101
    invoke-interface {v2, v3, v4}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    .line 104
    iget-object v3, p0, Lcom/sponsorpay/sdk/android/advertiser/AbstractCallbackSender;->mState:Lcom/sponsorpay/sdk/android/advertiser/SponsorPayAdvertiserState;

    invoke-virtual {v3}, Lcom/sponsorpay/sdk/android/advertiser/SponsorPayAdvertiserState;->getInstallSubId()Ljava/lang/String;

    move-result-object v1

    .line 106
    .local v1, installSubId:Ljava/lang/String;
    invoke-static {v1}, Lcom/sponsorpay/sdk/android/utils/StringUtils;->notNullNorEmpty(Ljava/lang/String;)Z

    move-result v3

    if-eqz v3, :cond_2

    .line 107
    const-string v3, "subid"

    invoke-interface {v2, v3, v1}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    .line 110
    :cond_2
    invoke-virtual {p0}, Lcom/sponsorpay/sdk/android/advertiser/AbstractCallbackSender;->getBaseUrl()Ljava/lang/String;

    move-result-object v3

    iget-object v4, p0, Lcom/sponsorpay/sdk/android/advertiser/AbstractCallbackSender;->mCredentials:Lcom/sponsorpay/sdk/android/credentials/SPCredentials;

    invoke-static {v3, v4}, Lcom/sponsorpay/sdk/android/utils/UrlBuilder;->newBuilder(Ljava/lang/String;Lcom/sponsorpay/sdk/android/credentials/SPCredentials;)Lcom/sponsorpay/sdk/android/utils/UrlBuilder;

    move-result-object v3

    invoke-virtual {v3, v2}, Lcom/sponsorpay/sdk/android/utils/UrlBuilder;->addExtraKeysValues(Ljava/util/Map;)Lcom/sponsorpay/sdk/android/utils/UrlBuilder;

    move-result-object v3

    .line 111
    const/4 v4, 0x0

    invoke-virtual {v3, v4}, Lcom/sponsorpay/sdk/android/utils/UrlBuilder;->sendUserId(Z)Lcom/sponsorpay/sdk/android/utils/UrlBuilder;

    move-result-object v3

    invoke-virtual {v3}, Lcom/sponsorpay/sdk/android/utils/UrlBuilder;->addScreenMetrics()Lcom/sponsorpay/sdk/android/utils/UrlBuilder;

    move-result-object v3

    invoke-virtual {v3}, Lcom/sponsorpay/sdk/android/utils/UrlBuilder;->buildUrl()Ljava/lang/String;

    move-result-object v0

    .line 113
    .local v0, callbackUrl:Ljava/lang/String;
    const-class v3, Lcom/sponsorpay/sdk/android/advertiser/AbstractCallbackSender;

    invoke-virtual {v3}, Ljava/lang/Class;->getSimpleName()Ljava/lang/String;

    move-result-object v3

    .line 114
    new-instance v4, Ljava/lang/StringBuilder;

    const-string v5, "Callback will be sent to: "

    invoke-direct {v4, v5}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v4, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v4

    invoke-virtual {v4}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v4

    .line 113
    invoke-static {v3, v4}, Lcom/sponsorpay/sdk/android/utils/SponsorPayLogger;->d(Ljava/lang/String;Ljava/lang/String;)V

    .line 116
    return-object v0
.end method


# virtual methods
.method protected varargs doInBackground([Ljava/lang/String;)Ljava/lang/Boolean;
    .locals 11
    .parameter "params"

    .prologue
    const/4 v10, 0x0

    .line 137
    const/4 v6, 0x0

    .line 139
    .local v6, returnValue:Ljava/lang/Boolean;
    aget-object v0, p1, v10

    .line 141
    .local v0, callbackUrl:Ljava/lang/String;
    new-instance v3, Lorg/apache/http/client/methods/HttpGet;

    invoke-direct {v3, v0}, Lorg/apache/http/client/methods/HttpGet;-><init>(Ljava/lang/String;)V

    .line 142
    .local v3, httpRequest:Lorg/apache/http/client/methods/HttpGet;
    invoke-static {}, Lcom/sponsorpay/sdk/android/utils/SPHttpClient;->getHttpClient()Lorg/apache/http/client/HttpClient;

    move-result-object v2

    .line 145
    .local v2, httpClient:Lorg/apache/http/client/HttpClient;
    :try_start_0
    invoke-interface {v2, v3}, Lorg/apache/http/client/HttpClient;->execute(Lorg/apache/http/client/methods/HttpUriRequest;)Lorg/apache/http/HttpResponse;

    move-result-object v4

    .line 149
    .local v4, httpResponse:Lorg/apache/http/HttpResponse;
    invoke-interface {v4}, Lorg/apache/http/HttpResponse;->getStatusLine()Lorg/apache/http/StatusLine;

    move-result-object v7

    invoke-interface {v7}, Lorg/apache/http/StatusLine;->getStatusCode()I

    move-result v5

    .line 151
    .local v5, responseStatusCode:I
    invoke-interface {v4}, Lorg/apache/http/HttpResponse;->getEntity()Lorg/apache/http/HttpEntity;

    move-result-object v7

    invoke-interface {v7}, Lorg/apache/http/HttpEntity;->consumeContent()V

    .line 153
    const/16 v7, 0xc8

    if-ne v5, v7, :cond_0

    .line 154
    const/4 v7, 0x1

    invoke-static {v7}, Ljava/lang/Boolean;->valueOf(Z)Ljava/lang/Boolean;

    move-result-object v6

    .line 159
    :goto_0
    const-class v7, Lcom/sponsorpay/sdk/android/advertiser/AbstractCallbackSender;

    invoke-virtual {v7}, Ljava/lang/Class;->getSimpleName()Ljava/lang/String;

    move-result-object v7

    new-instance v8, Ljava/lang/StringBuilder;

    const-string v9, "Server returned status code: "

    invoke-direct {v8, v9}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    .line 160
    invoke-virtual {v8, v5}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v8

    invoke-virtual {v8}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v8

    .line 159
    invoke-static {v7, v8}, Lcom/sponsorpay/sdk/android/utils/SponsorPayLogger;->d(Ljava/lang/String;Ljava/lang/String;)V

    .line 166
    .end local v4           #httpResponse:Lorg/apache/http/HttpResponse;
    .end local v5           #responseStatusCode:I
    :goto_1
    return-object v6

    .line 156
    .restart local v4       #httpResponse:Lorg/apache/http/HttpResponse;
    .restart local v5       #responseStatusCode:I
    :cond_0
    const/4 v7, 0x0

    invoke-static {v7}, Ljava/lang/Boolean;->valueOf(Z)Ljava/lang/Boolean;
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v6

    goto :goto_0

    .line 161
    .end local v4           #httpResponse:Lorg/apache/http/HttpResponse;
    .end local v5           #responseStatusCode:I
    :catch_0
    move-exception v1

    .line 162
    .local v1, e:Ljava/lang/Exception;
    invoke-static {v10}, Ljava/lang/Boolean;->valueOf(Z)Ljava/lang/Boolean;

    move-result-object v6

    .line 163
    const-class v7, Lcom/sponsorpay/sdk/android/advertiser/AbstractCallbackSender;

    invoke-virtual {v7}, Ljava/lang/Class;->getSimpleName()Ljava/lang/String;

    move-result-object v7

    .line 164
    new-instance v8, Ljava/lang/StringBuilder;

    const-string v9, "An exception occurred when trying to send advertiser callback: "

    invoke-direct {v8, v9}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v8, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;

    move-result-object v8

    invoke-virtual {v8}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v8

    .line 163
    invoke-static {v7, v8}, Lcom/sponsorpay/sdk/android/utils/SponsorPayLogger;->e(Ljava/lang/String;Ljava/lang/String;)V

    goto :goto_1
.end method

.method protected bridge varargs synthetic doInBackground([Ljava/lang/Object;)Ljava/lang/Object;
    .locals 1
    .parameter

    .prologue
    .line 1
    check-cast p1, [Ljava/lang/String;

    invoke-virtual {p0, p1}, Lcom/sponsorpay/sdk/android/advertiser/AbstractCallbackSender;->doInBackground([Ljava/lang/String;)Ljava/lang/Boolean;

    move-result-object v0

    return-object v0
.end method

.method protected abstract getAnswerReceived()Ljava/lang/String;
.end method

.method protected abstract getBaseUrl()Ljava/lang/String;
.end method

.method protected abstract getParams()Ljava/util/Map;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "()",
            "Ljava/util/Map",
            "<",
            "Ljava/lang/String;",
            "Ljava/lang/String;",
            ">;"
        }
    .end annotation
.end method

.method protected onPostExecute(Ljava/lang/Boolean;)V
    .locals 0
    .parameter "callbackWasSuccessful"

    .prologue
    .line 181
    invoke-virtual {p0, p1}, Lcom/sponsorpay/sdk/android/advertiser/AbstractCallbackSender;->processRequest(Ljava/lang/Boolean;)V

    .line 182
    return-void
.end method

.method protected bridge synthetic onPostExecute(Ljava/lang/Object;)V
    .locals 0
    .parameter

    .prologue
    .line 1
    check-cast p1, Ljava/lang/Boolean;

    invoke-virtual {p0, p1}, Lcom/sponsorpay/sdk/android/advertiser/AbstractCallbackSender;->onPostExecute(Ljava/lang/Boolean;)V

    return-void
.end method

.method protected abstract processRequest(Ljava/lang/Boolean;)V
.end method

.method public setCustomParams(Ljava/util/Map;)V
    .locals 0
    .parameter
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/util/Map",
            "<",
            "Ljava/lang/String;",
            "Ljava/lang/String;",
            ">;)V"
        }
    .end annotation

    .prologue
    .line 75
    .local p1, customParams:Ljava/util/Map;,"Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;"
    iput-object p1, p0, Lcom/sponsorpay/sdk/android/advertiser/AbstractCallbackSender;->mCustomParams:Ljava/util/Map;

    .line 76
    return-void
.end method

.method public trigger()V
    .locals 3

    .prologue
    .line 86
    const/4 v0, 0x1

    new-array v0, v0, [Ljava/lang/String;

    const/4 v1, 0x0

    invoke-direct {p0}, Lcom/sponsorpay/sdk/android/advertiser/AbstractCallbackSender;->buildUrl()Ljava/lang/String;

    move-result-object v2

    aput-object v2, v0, v1

    invoke-virtual {p0, v0}, Lcom/sponsorpay/sdk/android/advertiser/AbstractCallbackSender;->execute([Ljava/lang/Object;)Landroid/os/AsyncTask;

    .line 87
    return-void
.end method
